using System;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;
using UnityEngine.Events;
using Yoozoo.UI;
using Yoozoo.UI.YGUI;

public class YSliderBinder : BinderBase
{
    public enum AttributeType : int
    {
        tween,
        tweenDuration,
        onTweenComplete,
        minValue,
        maxValue,
        wholeNumbers,
        value,
        normalizedValue,
        onValueChanged,
        interactable,
        enabled,
    }
    
    private YSlider _target;
    
    public YSliderBinder(UIExpansion owner, LinkerConfig config) : base(owner, config)
    {
    }

    public YSliderBinder()
    {
        
    }

    public override void Dispose()
    {
        _target = null;
        base.Dispose();
    }

    public override void Init(LinkerConfig config)
    {
        GameObject targetGo = _owner.GetStoredGameObject(config.StoredGameObjectIndex);
        if (targetGo == null)
        {
            return;
        }
        _target = targetGo.GetComponent<YSlider>();
        _active = _target != null;
    }
    public override void SetBoolean(bool value)
    {
        switch ((AttributeType)Enum.Parse(typeof(AttributeType), _linkerType))
        {
            case AttributeType.tween:
                _target.tween = value;
            break;
            case AttributeType.wholeNumbers:
                _target.wholeNumbers = value;
            break;
            case AttributeType.interactable:
                _target.interactable = value;
            break;
            case AttributeType.enabled:
                _target.enabled = value;
            break;
            default:
            break;
        }
        base.SetBoolean(value);
    }
    
    public override void SetSingle(float value)
    {
        switch ((AttributeType)Enum.Parse(typeof(AttributeType), _linkerType))
        {
            case AttributeType.tweenDuration:
                _target.tweenDuration = value;
            break;
            case AttributeType.minValue:
                _target.minValue = value;
            break;
            case AttributeType.maxValue:
                _target.maxValue = value;
            break;
            case AttributeType.value:
                _target.value = value;
            break;
            case AttributeType.normalizedValue:
                _target.normalizedValue = value;
            break;
            default:
            break;
        }
        base.SetSingle(value);
    }
    
    public override void SetAction2(UnityAction action)
    {
        switch ((AttributeType)Enum.Parse(typeof(AttributeType), _linkerType))
        {
            case AttributeType.onTweenComplete:
                _target.onTweenComplete.AddListener(action);
            break;
            default:
            break;
        }
        base.SetAction2(action);
    }
    
    public override void RemoveAction2(UnityAction action)
    {
        switch ((AttributeType)Enum.Parse(typeof(AttributeType), _linkerType))
        {
            case AttributeType.onTweenComplete:
                _target.onTweenComplete.RemoveListener(action);
            break;
            default:
            break;
        }
        base.RemoveAction2(action);
    }
    
    public override void SetActionSingle(UnityAction<float> action)
    {
        switch ((AttributeType)Enum.Parse(typeof(AttributeType), _linkerType))
        {
            case AttributeType.onValueChanged:
                _target.onValueChanged.AddListener(action);
            break;
            default:
            break;
        }
        base.SetActionSingle(action);
    }
    
    public override void RemoveActionSingle(UnityAction<float> action)
    {
        switch ((AttributeType)Enum.Parse(typeof(AttributeType), _linkerType))
        {
            case AttributeType.onValueChanged:
                _target.onValueChanged.RemoveListener(action);
            break;
            default:
            break;
        }
        base.RemoveActionSingle(action);
    }
    
    public override void RemoveAllAction()
    {
        switch ((AttributeType)Enum.Parse(typeof(AttributeType), _linkerType))
        {
            case AttributeType.onTweenComplete:
                _target.onTweenComplete.RemoveAllListeners();
            break;
            case AttributeType.onValueChanged:
                _target.onValueChanged.RemoveAllListeners();
            break;
            default:
            break;
        }
    }
    
}